package com.lzy.cloud.order.controller;

import com.lzy.cloud.order.dtos.OrderAssessDto;
import com.lzy.cloud.order.request.OrderAssessRequest;
import com.lzy.cloud.order.response.OrderAssessResponse;
import com.lzy.cloud.order.service.OrderAssessService;
import com.lzy.framework.core.ensure.Ensure;
import com.lzy.framework.core.output.Result;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单评论主表
 * Created by WIN7 on 2018/6/6.
 */
@RestController
@RequestMapping("/order/assess")
public class OrderAssessController {

    @Autowired
    private OrderAssessService orderAssessService;

    /**
     * 根据订单id查询订单评论
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/find/by/order/id/{orderId}",method = RequestMethod.GET)
    public Result queryListByOrderId(@PathVariable("orderId") String orderId) {
        Ensure.that(orderId).isNotNull("00010003");
        OrderAssessDto orderAssessDto = orderAssessService.queryByOrderId(orderId);
        return new Result(DozerUtils.map(orderAssessDto, OrderAssessResponse.class));
    }

    /**
     * 新增订单评论
     * @param request
     * @return
     */
    @RequestMapping(value = "/create",method = RequestMethod.POST)
    public Result create(@RequestBody OrderAssessRequest request) {
        Ensure.that(request).isNotNull("00000002");
        Long id = orderAssessService.create(DozerUtils.map(request, OrderAssessDto.class));
        Ensure.that(id).isGt(0, "00110001");
        return new Result(id);
    }
}
